package com.sdy.healthcode.web.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.sdy.healthcode.biz.service.BulidingFloorInfoService;
import com.sdy.common.utils.DateUtil;
import com.sdy.common.utils.StringUtil;
import com.sdy.healthcode.biz.model.BulidingFloorInfo;
import com.sdy.common.model.Response;
import com.sdy.healthcode.biz.utils.TreeUtil;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.sdy.mvc.controller.BaseController;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * <p>
 * 楼宇&楼层信息 前端控制器
 * </p>
 *
 * @author hyh
 * @since 2020-03-10
 */
@Slf4j
@RestController
@SuppressWarnings("unchecked")
@Api(tags = "楼层信息API")
@RequestMapping("/bulidingFloorInfo")
public class BulidingFloorInfoController extends BaseController {
    @Autowired
    private BulidingFloorInfoService bulidingFloorInfoService;

    /**
     * 根据pId获取子节点数据
     *
     * @return
     */
    @GetMapping("/getTreeList")
    public Response getTreeList() {
        List<BulidingFloorInfo> result = bulidingFloorInfoService.list();
        List<BulidingFloorInfo> floorInfos = TreeUtil.toTree(result, "id", "parentId", null, BulidingFloorInfo.class);
        floorInfos.forEach(floor -> {
            if (!floor.getChildren().isEmpty()) {
                floor.getChildren().forEach(floorChild -> {
                    floorChild.setChildren(null);
                    floorChild.setShow(false);
                });
            }
        });
        return Response.success(floorInfos);
    }
}
